From: Jo-Philipp Wich Date: Thu, 28 Apr 2022 14:06:25 +0000 (+0200) Subject: luci-base: ui: resolve aliases and rewrites on obtaining menu node children X-Git-Url: http://git.openwrt.org/%22https:/collectd.org//%22/%22https:/collectd.org/%22?a=commitdiff_plain;h=fc759abeab1d80b6ba4b2d39ad4f61304832bb4f;p=project%2Fluci.git luci-base: ui: resolve aliases and rewrites on obtaining menu node children Extend LuCI.ui.menu.getChildren() to resolve aliases and rewrites prior to returning the menu nodes. This allows aliasing entire menu trees instead of just single pages. Signed-off-by: Jo-Philipp Wich (cherry picked from commit 180d39dcd2427e3c32c0ec7ecc3c7bfb48c0d0ab) --- diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js index a66f2519c5..447bcbae09 100644 --- a/modules/luci-base/htdocs/luci-static/resources/ui.js +++ b/modules/luci-base/htdocs/luci-static/resources/ui.js @@ -3125,7 +3125,24 @@ var UIMenu = baseclass.singleton(/** @lends LuCI.ui.menu.prototype */ { if (!node.children[k].hasOwnProperty('title')) continue; - children.push(Object.assign(node.children[k], { name: k })); + var subnode = Object.assign(node.children[k], { name: k }); + + if (L.isObject(subnode.action) && subnode.action.path != null && + (subnode.action.type == 'alias' || subnode.action.type == 'rewrite')) { + var root = this.menu, + path = subnode.action.path.split('/'); + + for (var i = 0; root != null && i < path.length; i++) + root = L.isObject(root.children) ? root.children[path[i]] : null; + + if (root) + subnode = Object.assign({}, subnode, { + children: root.children, + action: root.action + }); + } + + children.push(subnode); } return children.sort(function(a, b) {